<template>
    <PageView>
        <a-card title="列表">
            <a-row :gutter="10" class="inputGroup">
                <a-col :xs="12" :md="6" :lg="6" :xl="4">
                    <a-input v-model="searchData.username" placeholder="请输入账号" @keyup.enter="getListTwo"/>
                </a-col>
                <a-col :xs="12" :md="6" :lg="6" :xl="4">
                    <a-button-group>
                        <a-button type="primary" :loading="loading" @click="getListTwo">确定筛选</a-button>
                    </a-button-group>
                </a-col>
            </a-row>
            <a-table
                :loading="loading"
                :columns="columns"
                :dataSource="data"
                :pagination="{total,pageSize,showSizeChanger,current}"
                @change="changePagination"
                bordered :scroll="{x:true}">
            </a-table>
        </a-card>

        <a-modal title="打款凭证" v-model="visible" @ok="visible = false">
            <img :src="pingzhenImg" alt="" style="width: 100%">
        </a-modal>
    </PageView>
</template>

<script type="text/jsx">
    import Member from '../../api/Member'
    import { static_level, level } from '../../utils/status'
    export default {
        name: 'teamCaptain',
        data () {
            return {
                loading: true,
                visible: false,
                pingzhenImg: '',
                columns: [
                    {
                        title: '会员名',
                        dataIndex: 'username'
                    },
                    {
                        title: '充值金额',
                        dataIndex: 'money'
                    },
                    {
                        title: '打款凭证',
                        dataIndex: 'image',
                        customRender: (v) => {
                            return <img style="width: 50px" src={v} alt="" onClick={this.viewImg.bind(this, v)}/>
                        }
                    },
                    {
                        title: '状态',
                        dataIndex: 'status',
                        customRender: (v) => {
                            // 1审核中 2审核完成 -1审核驳回
                            return v === '1'?'审核中':v ==='2'?'审核完成':'审核驳回'
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        dataIndex: 'id',
                        width: 110,
                        customRender: (v, params) => {
                            console.log(params)
                            if (params.status !== '1') return '暂无操作'
                            return (
                                <a-dropdown>
                                    <a-menu slot="overlay">
                                        <a-menu-item style="color: green" onClick={() => {
                                            this.activationSave(v, 1)
                                        }}>通过
                                        </a-menu-item>
                                        <a-menu-item style="color: red" onClick={() => {
                                            this.activationSave(v, 2)
                                        }}>驳回
                                        </a-menu-item>
                                    </a-menu>
                                    <a-button>操作 <a-icon type="down"/></a-button>
                                </a-dropdown>
                            )
                        }
                    }
                ],
                data: [],
                total: 0,
                pageSize: 10,
                current: 1,
                showSizeChanger: true,
                searchData: {
                    username: '',
                },
            }
        },
        activated () {
            this.getList()
        },
        methods: {
            getListTwo () {
                this.current = 1
                this.getList()
            },
            getList () {
                this.loading = true
                Member.activationList({
                    page: this.current,
                    num: this.pageSize,
                    ...this.searchData
                }).then(res => {
                    this.data = res.data.map((value, key) => {
                        return { ...value, key }
                    })
                    this.loading = false
                    this.total = parseInt(res.count)
                })
            },
            changePagination (pagination) {
                Object.keys(pagination).forEach(val => {
                    this[val] = pagination[val]
                })
                this.getList()
            },
            del (uid) {
                this.$confirm({
                    title: `撤销`,
                    content: `确定要撤销团队长吗?`,
                    centered: true,
                    onOk: () => {
                        return new Promise((resolve, reject) => {
                            Member.delCaptain({ uid }).then(res => {
                                resolve()
                                this.getList()
                            }).catch(res => {
                                reject()
                            })
                        })
                    }
                })
            },
            viewImg(v) {
                console.log(v);
                this.pingzhenImg = v;
                this.visible = true;
            },
            activationSave(id, type) {
                Member.activationSave({id, type}).then(res => {
                    this.getList()
                }).catch(res => {

                })
            }
        }
    }
</script>

<style scoped lang="less">
    .inputGroup {
        > div {
            margin-bottom: 20px;
        }
    }
</style>